home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / xview / genial / func / move_point.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-14  |  2.3 KB  |  98 lines

  1. /*
  2.  * move_point.c -- routines for moving individual points in a plist
  3.  *
  4.  * uses an experimental claim_state() interface to temporarily claim control
  5.  * of the UI
  6.  *
  7.  */
  8.  
  9. #include "common.h"
  10. #include "llist.h"
  11. #include "display.h"
  12. #include "ui.h"
  13. #include "reg.h"
  14. #include "log.h"
  15. #include "sm.h"
  16.  
  17. struct plist *mpt;        /* point which we are moving */
  18.  
  19. /* move_point(): given an (x,y) position of the mouse, find nearest point and
  20.  * interactively move it until the button is released.
  21.  *
  22.  */
  23.  
  24. move_point(x, y)
  25.     int       x, y;
  26. {
  27.     int       move_dispatch();
  28.     XPoint    pt;
  29.  
  30. #ifdef TRACE_EX
  31.      fprintf(stderr, "in move_point \n");
  32. #endif
  33.  
  34.     /*
  35.      * claim the state so that we can intercept mouse events to achieve an
  36.      * interactive move
  37.      */
  38.     dp_push(move_dispatch);
  39.     /* fill mpt appropriately */
  40.     pt.x = x;
  41.     pt.y = y;
  42. #ifdef DEBUG
  43.     printf("moving point at (%d,%d)\n", x, y);
  44. #endif
  45.     mpt = pfind(pt);
  46.     if (mpt == NULL) {
  47.     printf("No such point near position (%d,%d)!\n", x,y);
  48.     XBell(display, 0);
  49.     dp_del(move_dispatch);
  50.     }
  51. }
  52.  
  53. /***************************************************************/
  54. int
  55. move_dispatch(token, arg)
  56.     int       token;        /* token as defined in sm.h */
  57.     caddr_t   arg;        /* pointer to an optional argument */
  58. {
  59.     struct plist *getcpl();
  60.  
  61.     if (token == IMG_BUT) {
  62.     /* move the points */
  63.     /* replace old cross */
  64.     ref_cb(img_win->d_xid, &mpt->cb);
  65.     /* and draw a new one */
  66.     mpt->pt.x = dtoi(event_x((Event *) arg));
  67.     mpt->pt.y = dtoi(event_y((Event *) arg));
  68. #ifdef DEBUG
  69.     printf("dispatch: moving point at (%d,%d)\n",
  70.            (int) mpt->pt.x, (int) mpt->pt.y);
  71. #endif
  72.     cbget(orig_ximg, &mpt->cb, mpt->pt);
  73.     XSetForeground(display, gc, standout);
  74.     draw_cb(img_win->d_xid, &mpt->cb);
  75.     if ((event_action((Event *) arg) == LOC_DRAG) &&
  76.         (event_is_down((Event *) arg))) {
  77.             return dispatch_next(token,(char **)arg);
  78.     } else {
  79. #ifdef DEBUG
  80.         printf("clearing move_dispatch() from the dispatch stack \n");
  81. #endif
  82.         dp_del(move_dispatch);
  83.  
  84.         if (curfunc->reg != NULL) {
  85.         refresh_reg(curfunc->reg);    /* refresh points under old line */
  86.         if (curfunc->reg->r_dlist != NULL) {
  87.             curfunc->reg->r_dlist->len = 0;
  88.             curfunc->reg->r_dlist->prev =
  89.             curfunc->reg->r_dlist->next = NULL;
  90.             curfunc->reg->r_dlist->flags = 0;
  91.         }
  92.         }
  93.         pvreg_set(getcpl());
  94.     }
  95.     }
  96.     return dispatch_next(token,(char **)arg);
  97. }
  98.